﻿@model AccountManageViewModel
@{
	var phoneLabel = Model.PhoneNumber == null ? "(未绑定手机)" : Model.PhoneNumberConfirmed ? "" : "(未验证)";
	var emailLabel = Model.Email == null ? "(未绑定邮箱)" : Model.EmailConfirmed ? "" : "(未验证)";
	var phoneButton = Model.HasPhoneNumber ? "更换号码" : "绑定手机";
}

<div class="p-4">
	<h3>账号管理</h3>
	<hr>
	@* 手机号 *@
	<div>
		<dt>手机号@(phoneLabel)</dt>
		<form method="get" asp-controller="Manage" asp-action="ChangePhoneNumber">
			<input asp-for="PhoneNumber" type="text" disabled/>
			<button class="btn btn-secondary">@phoneButton</button>
		</form>
	</div>
	@* 邮箱 *@
	<div class="mt-2">
		<div>
			<dt>
				邮箱@(emailLabel)
				@* 邮箱未添加 *@
				@if (!Model.EmailConfirmed)
				{
					<a asp-controller="Manage" asp-action="ConfirmEmail" asp-route-email="@Model.Email">验证</a>
				}
			</dt>
		</div>
		<form method="get" asp-controller="Manage" asp-action="ChangeEmail">
			<input asp-for="Email" type="text" disabled/>
			<button class="btn btn-secondary">更换邮箱</button>
		</form>

	</div>
	@* 密码 *@
	<div class="mt-2">
		<div>
			<dt>密码</dt>
		</div>
		<form method="get" asp-controller="Manage" asp-action="ChangePassword">
			<input value="********" type="password" disabled/>
			<button class="btn btn-secondary">密码修改</button>
		</form>
	</div>
	@* 双因素认证 *@
	<div class="mt-2 col-4">
		<dt>双因素认证</dt>
		<table class="table table-bordered text-center align-middle">
			<tr>
				<td>状态</td>
				<td>操作</td>
			</tr>
			<tr>
				@if (Model.TwoFactorEnabled)
				{
					<td>
						<span class="text-success">启用</span>
					</td>
					<td>
						<form asp-controller="Manage" asp-action="DisableTwoFactorAuthentication">
							<button type="submit" class="btn btn-link">关闭</button>
						</form>
					</td>
				}
				else
				{
					<td>
						<span class="text-warning">关闭</span>
					</td>
					<td>
						<form asp-controller="Manage" asp-action="EnableTwoFactorAuthentication">
							<button class="btn btn-link">启动</button>
						</form>
					</td>
				}
			</tr>
		</table>
	</div>
	@* 鉴权器 *@
	<div class="mt-2">
		<dt>鉴权 App:</dt>
		<dd>
			@if (Model.AuthenticatorKey == null)
			{
				<form asp-controller="Manage" asp-action="ResetAuthenticatorKey" method="post" class="form-horizontal" role="form">
					AuthenticatorKey: [<button type="submit" class="btn btn-link">生成</button>]
				</form>
			}
			else
			{
				<text>AuthenticatorKey: @Model.AuthenticatorKey</text>
				<form asp-controller="Manage" asp-action="GenerateRecoveryCode" method="post" class="form-horizontal" role="form">
					RecoveryCode: [<button type="submit" class="btn btn-link">生成新的恢复代码</button>]
				</form>
			}
		</dd>
	</div>
	@* 第三方账户关联 *@
	<div class="mt-2">
		<div>第三方账户关联</div>
		<div>当前三方账户关联数量：@Model.CurrentUserLogins.Count</div>
		<a asp-controller="Manage" asp-action="ManageLogins">去管理</a>
	</div>
</div>
